package com.longrise.co.ui.mine.fragment;

import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.longrise.co.R;
import com.longrise.co.api.CommonPara;
import com.longrise.co.ui.mine.contract.MineContract;
import com.longrise.co.ui.mine.model.MineModel;
import com.longrise.co.ui.mine.presenter.MinePresenter;
import com.ly.common.base.BaseFragment;
import com.ly.common.commonutils.StringUtils;

import butterknife.Bind;
import butterknife.OnClick;

/**
 * Created by luoyang on 2017-7-20.
 */

public class KckpSetFragment extends BaseFragment<MinePresenter, MineModel> implements MineContract.View<String> {

    @Bind(R.id.head_title)
    TextView headTitle;
    @Bind(R.id.suggest)
    EditText suggest;


    @Override
    protected int getLayoutResource() {
        return R.layout.fg_kckp_set;
    }

    @Override
    public void initPresenter() {
        mPresenter.setVM(this, mModel);
    }

    @Override
    protected void initView() {
        setText(headTitle, "快处快赔地址设置");
        suggest.setText(CommonPara.getInstance().getKckpUrl());
    }

    public static KckpSetFragment newInstance() {
        return new KckpSetFragment();
    }


    @OnClick({R.id.head_back, R.id.submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.head_back:
                _mActivity.onBackPressed();
                break;
            case R.id.submit:
                if(StringUtils.isEmpty(suggest.getText().toString().trim())) {
                    showLongToast("快处快赔地址不能为空");
                    return ;
                }
                CommonPara.getInstance().setKckpUrl(suggest.getText().toString().trim());
                showLongToast("设置成功！");
                _mActivity.onBackPressed();
                break;
        }
    }

    @Override
    public void requestSuccess(String s) {
        showLongToast("用户反馈成功！");
        _mActivity.onBackPressed();
    }

    @Override
    public void onRequestComplete() {

    }
}
